package com.work.crops.dao;

import com.work.crops.pojo.CropsInfo;
import com.work.crops.pojo.CropsParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CropsInfoMapper extends Mapper<CropsInfo> {

    @Select("<script>" +
            "select * from t_crops_info" +
            " <where>" +
            "<if test=\"name != null and name != ''\"> name  like '%' #{name} '%' </if>" +
            "<if test=\"alias != null and alias != ''\">or alias like '%' #{alias} '%'</if> " +
            "<if test=\"region != null and region != ''\"> or region like '%' #{region} '%'</if> " +
            "</where>" +
            "</script>")
    List<CropsInfo> findPage(CropsParam cropsParam);


    @Select("SELECT count(1) FROM t_device_index WHERE iid in(SELECT iid FROM t_crops_info_index WHERE cid = #{id})")
    Integer findIndexIfBindDevice(String id);
}
